/*
 * Copyright 2022-2023 Advanced Micro Devices Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <iostream>
#include <vector>

using namespace std;

class FtdHungarian {
 public:
  FtdHungarian();
  ~FtdHungarian();
  void Solve(vector<vector<double> > &DistMatrix, vector<int> &Assignment);

 private:
  void assignmentoptimal(int *assignment, double *cost, double *distMatrix,
                         int nOfRows, int nOfColumns);
  void buildassignmentvector(int *assignment, bool *starMatrix, int nOfRows,
                             int nOfColumns);
  void computeassignmentcost(int *assignment, double *cost, double *distMatrix,
                             int nOfRows);
  void step2a(int *assignment, double *distMatrix, bool *starMatrix,
              bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
              bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
  void step2b(int *assignment, double *distMatrix, bool *starMatrix,
              bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
              bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
  void step3(int *assignment, double *distMatrix, bool *starMatrix,
             bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
             bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
  void step4(int *assignment, double *distMatrix, bool *starMatrix,
             bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
             bool *coveredRows, int nOfRows, int nOfColumns, int minDim,
             int row, int col);
  void step5(int *assignment, double *distMatrix, bool *starMatrix,
             bool *newStarMatrix, bool *primeMatrix, bool *coveredColumns,
             bool *coveredRows, int nOfRows, int nOfColumns, int minDim);
};
